package com.rentcars.controller;


import com.github.pagehelper.PageInfo;
import com.rentcars.entity.Clientuser;
import com.rentcars.service.ClientuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;


/**
 * @author 任梦强
 * @date 2021.3.4
 */
@RestController
public class ClientuserController {

    @Autowired
    private ClientuserService clientuserService;

    @RequestMapping("/client")
    public PageInfo<Clientuser> selectAllClientuser(Clientuser clientuser,Integer curr, Integer pageSize){
        return  clientuserService.selectAllClientuser(clientuser,curr,pageSize);
    }

    @RequestMapping("/client-list")
    public ModelAndView toLike(){
        return new ModelAndView("client-list");
    }

    @RequestMapping("/client-add")
    public ModelAndView toAdd(){
        return new ModelAndView("client-add");
    }

    @RequestMapping("/clientAdd")
    public Integer insertClientUser(Clientuser clientuser, HttpSession session){
        return clientuserService.insertClientUser(clientuser);
    }

    @RequestMapping("/editPage")
    public ModelAndView findUser(String uid){
        Clientuser clientuser=clientuserService.selectClientUserById(uid);
        Map<String,Object>map=new HashMap<>();
        map.put("data",clientuser);
        return new ModelAndView("client-edit",map);
    }

    @RequestMapping("/edit")
    public int editClientUser(Clientuser clientuser){
        return clientuserService.updateClientUser(clientuser);

    }

    /**
     * 根据ID删除
     * @param uid
     * @return
     */
    @RequestMapping("/del")
    public int deleteByPrimaryKey(String uid){
        return clientuserService.deleteByPrimaryKey(uid);
    }

    /**
     * 批量删除
     * @param clientUsersuid 所有ID的list集合
     * @param request
     * @return
     */
    @RequestMapping("/delete")
    public int delClientUser(@RequestParam String clientUsersuid, HttpServletRequest request){
        List<String>uidList= Arrays.asList(clientUsersuid.split(","));
        return clientuserService.delClientUser(uidList);

    }


    public ClientuserService getClientuserService() {
        return clientuserService;
    }

    public void setClientuserService(ClientuserService clientuserService) {
        this.clientuserService = clientuserService;
    }
}
